package GUI;

import java.io.IOException;
import java.util.HashMap;
import java.util.LinkedList;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;

import GUI.CardImages.CardDeckGUI;

public class CardImages {
	public class CardDeckGUI {
		private String path;
		private String name;
		public CardDeckGUI(String path, String name) {
			this.path=path;
			this.name=name;
		}
		public String getPath() {
			return path;
		}
		public String getName() {
			return name;
		}
	}
	
	private CardDeckGUI currentDeck;
	private LinkedList<CardDeckGUI> availableDecks;
	private static CardImages instance = new CardImages();
	private HashMap<String, ImageIcon> cardIcons;
	
	private CardImages() {
		cardIcons = new HashMap<>();
		availableDecks = new LinkedList<>();
		availableDecks.add(new CardDeckGUI("/convClassic", "Klasyczne"));
		availableDecks.add(new CardDeckGUI("/convCrusades", "Krucjaty"));
		availableDecks.add(new CardDeckGUI("/convGrunwald", "Grunwald"));
		availableDecks.add(new CardDeckGUI("/convJKM", "JKM"));
		availableDecks.add(new CardDeckGUI("/convKim", "Kim Dzong Il"));
		currentDeck = availableDecks.getFirst();
	}
	
	public static CardImages getInstance() {
		return instance;
	}
	
	public ImageIcon getII(String path) {
		path = "/carddeck"+currentDeck.getPath()+path.substring(14)+".png";
		ImageIcon icon = cardIcons.get(path);
		if(icon==null) {
			try {
				icon = new ImageIcon(ImageIO.read(getClass().getResource(path)));
			} catch (IOException e) {
				e.printStackTrace();
			}
			cardIcons.put(path, icon);
		}
		return icon;
	}

	public LinkedList<CardDeckGUI> getDecks() {
		return availableDecks;
	}
	
	public CardDeckGUI getCurrentDeck() {
		return currentDeck;
	}

	public void changeDeck(int selectedIndex) {
		currentDeck = availableDecks.get(selectedIndex);
	}
}
